package com.lvmama.pangolin.conf;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.lvmama.pangolin.kafka.SpiderProductProcesser;

@Configuration
@EnableConfigurationProperties(KafkaSettings.class)
public class BeanConfig
{
	
	@Autowired
    private KafkaSettings kafkaSetting;
	
	@Bean
	public SpiderProductProcesser getSpiderProductProcesser()
	{
		Boolean consumer_start = kafkaSetting.getAuto_start();
		
		if(consumer_start)
		{
			int partition = kafkaSetting.getPartition();
			String bootstrap_servers = kafkaSetting.getBootstrap_servers();
			String topic_group_id = kafkaSetting.getTopic_group_id();
			String topic = kafkaSetting.getTopic();
			Boolean auto_commit = kafkaSetting.getAuto_commit();
			
			Properties properties = new Properties();
	        properties.put("bootstrap.servers", bootstrap_servers);
	        properties.put("enable.auto.commit", auto_commit);
	        properties.put("group.id", topic_group_id);
	        List<String> list = new ArrayList<String>();
	        list.add(topic);
	        return new SpiderProductProcesser(properties,partition,list);
		}
		else
			return null;
		
		
		
	}
}
